package cn.hdu.liang.condition;

import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class MyService {
    private Lock lock = new ReentrantLock();
    private Condition condition = lock.newCondition();


    public void await() {
        try {
            lock.lock();
            System.out.println(" await start 时间为 "+System.currentTimeMillis());
            condition.await();
            System.out.println(" await  end  时间为 "+System.currentTimeMillis());
        } catch(InterruptedException e) {
            e.printStackTrace();
        }finally {
            lock.unlock();
        }
    }

    public void signal() {
        try{
            lock.lock();
            System.out.println("Signal 时间为 "+System.currentTimeMillis());
            condition.signal();
        }finally {
            lock.unlock();
        }
    }
}
